package com.cincc.cinccimdemo.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.adapter.ConversationAdapter;
import com.cincc.cinccimdemo.common.GlideUtils;
import com.cincc.cinccimdemo.model.MessageInfoUI;
import com.cincc.im.model.enums.ImSendType;
import com.cincc.im.model.message.ImImageMessage;
import com.google.android.material.imageview.ShapeableImageView;

public class ReceiveImageViewHolder extends MessageContentHolder {
    public ImageView iv_face;
    public ShapeableImageView iv_message;
    public TextView tv_username;
    public TextView tv_time;
    public ProgressBar progress;
    public RelativeLayout rl_message;

    public ReceiveImageViewHolder(Context context, View itemView, ConversationAdapter adapter) {
        super(context, itemView, adapter);
        iv_face = itemView.findViewById(R.id.iv_face);
        iv_message = itemView.findViewById(R.id.iv_message);
        tv_username = itemView.findViewById(R.id.username_text);
        tv_time = itemView.findViewById(R.id.tv_time);
        progress = itemView.findViewById(R.id.progress);
        rl_message = itemView.findViewById(R.id.rl_message);
    }

    @Override
    public void bindView(MessageInfoUI uiMessage, int position) {
        super.bindView(uiMessage, position);
        ImImageMessage imImageMessage = (ImImageMessage) uiMessage.getMessageInfo().imMessage;
        GlideUtils.initImageWithFileCacheWithProgress(context, imImageMessage.thumb, iv_message, progress, 10);
        rl_message.setOnClickListener(v -> {
            preview(uiMessage);
        });
        tv_username.setText(uiMessage.getMessageInfo().senderName);
        tv_username.setVisibility(ImSendType.isP2P(uiMessage.getMessageInfo().imSendType) ? View.GONE : View.VISIBLE);
    }
}

